package org.sang.bbbig.config;


import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class InfluxDbConfig {
    @Value("${spring.influx.url:''}")
    private String url;

    @Value("${spring.influx.user:''}")
    private String name;

    @Value("${spring.influx.password:''}")
    private String password;

    @Value("${spring.influx.database:''}")
    private String database;



    public static String retentionPolicy = "autogen";

    @Bean
    public InfluxDB influxDB(){
        InfluxDB influxDB= InfluxDBFactory.connect(url,name,password);
        try {
            influxDB.setDatabase(database)
                    .enableBatch(100,1000, TimeUnit.MILLISECONDS);
        } catch (Exception e){
            e.printStackTrace();
        } finally {
            influxDB.setRetentionPolicy(retentionPolicy);
        }
        influxDB.setLogLevel(InfluxDB.LogLevel.BASIC);
        return influxDB;
    }
}
